/**
 * Created by superman on 17/2/16.
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from './components/login.vue'
import msg from './components/msg.vue'

import axios from './http'
import api from './constant/api'

Vue.use(VueRouter)

const routes = [
    {
        path: '/msg/:id',
        name: 'msg',
        meta: {
            requireAuth: true,
        },
        component: msg
    },
    {
        path: '/login',
        name: 'login',
        component: Login
    }
];


// // 页面刷新时，重新赋值token
// if (window.localStorage.getItem('token')) {
//     store.commit(types.LOGIN, window.localStorage.getItem('token'))
// }

const router = new VueRouter({
    routes
});

// router.beforeEach((to, from, next) => {
//     console.log('**********change route**********');
//     console.log(to,from);
//     console.log(to.meta.requireAuth);
//     if (to.meta.requireAuth) {
//         if (localStorage.token) {//有token才检查
//             axios.get(api.veryfiyToken, {})
//                 .then(res => {
//                     console.log('**********get token**********');
//                     console.log(JSON.stringify(res));
//                     if(res.data.status != 0){//无效跳到login
//                         next({path: '/login'})
//                     }else next();
//                 })
//         }
//         else {//没有跳转登录
//             next({ path: '/login'})
//         }
//     }
//     else {
//         next();
//     }
// })

export default router;